﻿@model Matrix.MaKaYunShang.Model.Dto.McAccountDto
@{
    ViewBag.Title = "订单管理";
    ViewBag.PathToBtn = "/Orders/List";
    ViewBag.TextBtn = "刷新";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section css{
    <style type="text/css">
        body {
            font-size: 25px !important;
        }
        .nav-tabs li {
            cursor: pointer;
        }
        .table hr {
            margin: 5px 0;
            border: dashed 1px #aaa;
        }
        .dataTables_info {
            font-size: 20px !important;
        }
        .divFrameTitle {
            display: none;
        }
    </style>
}
<div class="row" id="divSearch" style="display: none">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                开始时间：<input type="text" class="form-control input-sm form_datetime_order_search" placeholder="开始时间" style="width: 110px;display: inline-block" id="startTime" />
                &nbsp;&nbsp;
                结束时间：<input type="text" class="form-control input-sm form_datetime_order_search" placeholder="结束时间" style="width: 110px;display: inline-block" id="endTime" />
                <input type="hidden" id="hidOrderStatus" value="@ViewBag.OrderStatus" />
                <a class="btn btn-primary pull-right" id="btnSearch">查询</a>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                订单列表
            </div>
            <div class="panel-body">
                <ul class="nav nav-tabs" style="font-size: 20px;">
                    @if (ViewBag.IsOpenOrderGrab)
                    {
                        <li>
                            <a data-toggle="tab" tag="1">新订单</a>
                        </li>
                    }
                    <li>
                        <a data-toggle="tab" tag="2">正在配送</a>
                    </li>
                    <li>
                        <a data-toggle="tab" tag="-1">全部</a>
                    </li>
                </ul>
                <div class="dataTable_wrapper">
                    <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                        <thead>
                            <tr>
                                <th>操作</th>
                                <th>用户收货信息</th>
                                <th>商品信息</th>
                                <th>金额</th>
                                <th>付款方式</th>
                                <th>下单时间</th>
                                <th>备注</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@section javascript{
    <script src="~/Content/admin/dist/js/pagingHelper.js"></script>
    <script type="text/javascript">
        var dataParams = {};
        var serverProcessPath = "/Orders/Listing?orderStatus=@(ViewBag.OrderStatus)";
        var showColumns = [
            { data: "Action" },
            { data: "ConsumerInfo" },
            { data: "CommodityInfo" },
            { data: "PayPrice" },
            { data: "PayWay" },
            { data: "OrderTime" },
            { data: "Remark" }
        ];
        pagingHelper.Paging(serverProcessPath, dataParams, showColumns, null, false);
        $("#dataTables-example_wrapper div:first").hide();

        $(function () {
            $(".nav-tabs li a").click(function () {
                var tag = $(this).attr("tag");
                $("#hidOrderStatus").val(tag);
                reloadOrder();
            });

            $(".nav-tabs li a[tag='@(ViewBag.OrderStatus)']").parent().addClass("active").siblings().removeClass("active");

            $("#btnSearch").click(function () {
                reloadOrder();
            });

            $("divFrameTitle").hide();
        });

        function grab(id) {
            alertify.okBtn("确定").cancelBtn("取消").confirm("确认抢单？", function () {
                $.post("@Url.Action("Grab")", "orderId=" + id, function (data) {
                    if (data.Status) {
                        alertify.success(data.Message);
                        reloadOrder();
                    } else {
                        alertify.error(data.Message);
                    }
                });
            });
        }

        function arrived(id) {
            alertify.okBtn("确定").cancelBtn("取消").confirm("确认已送达？", function () {
                $.post("@Url.Action("Arrived")", "orderId=" + id, function (data) {
                    if (data.Status) {
                        alertify.success(data.Message);
                        reloadOrder();
                    } else {
                        alertify.error(data.Message);
                    }
                });
            });
        }

        function complete(id) {
            alertify.okBtn("确定").cancelBtn("取消").confirm("确认已完成？", function () {
                $.post("@Url.Action("Complete")", "orderId=" + id, function (data) {
                    if (data.Status) {
                        alertify.success(data.Message);
                        reloadOrder();
                    } else {
                        alertify.error(data.Message);
                    }
                });
            });
        }

        function reloadOrder() {
            pagingHelper.reloadWithDiffPath("@Url.Action("Listing")" + "?startTime=" + $("#startTime").val() + "&endTime=" + $("#endTime").val() + "&orderStatus=" + $("#hidOrderStatus").val());
        }
    </script>
}